﻿@model FieldControlViewModel
@{
	string dataVal = string.Empty;
	string dataValMsg = string.Empty;
	if (Model.EnableNull)
	{
		dataVal += " data-val-required=\"不能为空\" ";
	}
	if (!string.IsNullOrEmpty(dataVal))
	{
		dataVal += " data-val=\"true\" ";
		dataValMsg = " data-valmsg-for=\"" + Model.Prefix + Model.FieldName + "\" data-valmsg-replace=\"true\"";
	}
	var dummyObject = new[] { new { id = string.Empty, text = string.Empty } };
	var myObjects = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(Model.Tips, dummyObject);
	switch (Model.Settings[4])
	{
		case "1"://单选下拉框
		case "2"://多选下拉框
			<span class="select-box radius">
				<select class="layui-input" name="@Model.Prefix@Model.FieldName" id="@Model.Prefix@Model.FieldName" @Html.Raw(dataVal) lay-ignore></select>
			</span>
			break;
		case "3"://单选按纽
			for (int i = 0; i < myObjects.Length; i++)
			{
				if (myObjects[i].id == Model.FieldValue)
				{
					<input type="radio" name="@Model.Prefix@Model.FieldName" value="@myObjects[i].id" title="@myObjects[i].text" checked="checked">
				}
				else
				{
					<input type="radio" name="@Model.Prefix@Model.FieldName" value="@myObjects[i].id" title="@myObjects[i].text">
				}
				if (i > 0 && i % Model.Settings[6].ToInt32() == 0)
				{
					<br />
				}
			}
			break;
		case "4"://复选框
			for (int i = 0; i < myObjects.Length; i++)
			{
				if (StringHelper.FoundCharInArr(Model.FieldValue,myObjects[i].id.ToString()))
				{
					<input type="checkbox" name="@Model.Prefix@Model.FieldName" value="@myObjects[i].id" title="@myObjects[i].text" lay-skin="primary" checked="checked">
				}
				else
				{
					<input type="checkbox" name="@Model.Prefix@Model.FieldName" value="@myObjects[i].id" title="@myObjects[i].text" lay-skin="primary">
				}
				int index = i + 1;
				if (index % Model.Settings[6].ToInt32() == 0)
				{
					<br />
				}
			}
			break;
	}
}
<span class="layui-bg-green">@Model.Description</span>
<span style="color:red;" @Html.Raw(dataValMsg)></span>
@{
	if (Model.Settings[4] == "1" || Model.Settings[4] == "2")
	{
		<script type="text/javascript">
		function @{@Model.Prefix@Model.FieldName}InitListControl() {
			var showType = "@Model.Settings[4]";
			var selectID = "@Model.Prefix@Model.FieldName";
			var data = @Html.Raw(Model.Tips);
			var selectValue = "@Model.FieldValue";
			switch (showType) {
				case "1":
					initSelect2(selectID, data, selectValue, false);
					break;
				case "2":
					initSelect2(selectID, data, selectValue, true);
					break;
			}
		}
		jQuery(function () {
			@{@Model.Prefix@Model.FieldName}InitListControl();
		});
		</script>
	}
}
